package com.relatev.minecraft.UWantRestart.Bukkit;

import java.util.Iterator;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

public class BKRestartTasker {

    public static void restart(String tipmessage, int second) {

        Bukkit.getScheduler().runTaskTimer(UWantRestart.MainPlugin, new Runnable() {
            private int count = 0;

            @Override
            public void run() {
                Bukkit.broadcastMessage(tipmessage);
                if (count >= second) {
                    restart(tipmessage);
                }
                count++;
            }
        }, 0, 20);
    }

    public static void restart(String tipmessage) {
        Iterator<? extends Player> it = Bukkit.getOnlinePlayers().iterator();
        while (it.hasNext()) {
            Player player = it.next();
            player.kickPlayer(tipmessage);
        }
        Bukkit.shutdown();
    }
}
